package cn.easybuy.utils;

import java.util.List;

public class Page <T> {
    private Long pageIndex;     //页码
    private Long pageSize;      //页大小
    private Long totalCounts;   //数据的总数量
    private Long totalPages;    //总页数
    private Long startRows;     //起始行
    private List<T>  data;      //数据结果

    public Page() {
        this.pageIndex=1L;
        this.pageSize=10L;
    }

    public Page(Long pageIndex) {
        this(pageIndex, 5L);
    }

    public Page(Long pageIndex, Long pageSize) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.setStartRows((pageIndex - 1) * pageIndex);
    }

    public Long getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Long pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Long getPageSize() {
        return pageSize;
    }

    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotalCounts() {
        return totalCounts;
    }

    public void setTotalCounts(Long totalCounts) {
        this.totalCounts = totalCounts;
        this.setTotalPages(totalCounts % pageSize == 0 ? totalCounts / pageSize : totalCounts / pageSize + 1);
    }

    public Long getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Long totalPages) {
        this.totalPages = totalPages;
    }

    public Long getStartRows() {
        return startRows;
    }

    public void setStartRows(Long startRows) {
        this.startRows = startRows;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T>  data) {
        this.data = data;
    }
}
